import java.util.Random;

public class Game {
    private Player player;

    public Game(Player player) {
        super();
        this.player = player;
    }


    public String printStr() {
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < LevelParam.levels[player.getLevelNo() - 1].getStrLength(); i++) {
            int rand = random.nextInt(6);
            switch (rand) {
                case 0: {
                    buffer.append("1");
                    break;
                }
                case 1: {
                    buffer.append("2");
                    break;
                }
                case 2: {
                    buffer.append("3");
                    break;
                }
                case 3: {
                    buffer.append("4");
                    break;
                }
                case 4: {
                    buffer.append("5");
                    break;
                }
                case 5: {
                    buffer.append("6");
                    break;
                }
            }
        }
        System.out.println(buffer.toString());
        return buffer.toString();
    }
    public void printResult(String out,String in){

        if(out.equals(in)){
            long currentTime=System.currentTimeMillis();
            if((currentTime-player.getStartTime())/1000>LevelParam.levels[player.getLevelNo()-1].getTimeLimit()){
                System.out.println("游戏超时，闯关失败！");
                System.exit(1);
            }else {
                player.setCurrScore(player.getCurrScore()+LevelParam.levels[player.getLevelNo()-1].getPerScore());
                System.out.println("输入正确，您的积分是"+player.getCurrScore()+"分，" +
                        "您的级别是"+player.getLevelNo()+"级，" +
                        "您所用时间"+(currentTime-player.getStartTime())/1000+"秒");
                if(player.getLevelNo()==6){
                    int score=LevelParam.levels[player.getLevelNo()-1].getPerScore()*LevelParam.levels[player.getLevelNo()-1].getStrTime();
                    if(player.getCurrScore()==score){
                        System.out.println("闯关成功！！！");
                        System.exit(0);
                    }
                }
            }
        }else {
            System.out.println("输入错误，闯关失败！！！");
            System.exit(1);
        }
    }

}
